package com.hello.sky.controller.admin;

import com.hello.sky.model.dto.OrdersCancelDTO;
import com.hello.sky.model.dto.OrdersPageQueryDTO;
import com.hello.sky.model.dto.OrdersRejectionDTO;
import com.hello.sky.model.entity.OrderDetail;
import com.hello.sky.model.entity.Orders;
import com.hello.sky.model.vo.OrderStatisticsVO;
import com.hello.sky.model.vo.OrderVO;
import com.hello.sky.result.PageResult;
import com.hello.sky.result.Result;
import com.hello.sky.service.OrdersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author D
 */
@Slf4j
@RestController
@RequestMapping("/admin/order")
public class OrdersController {

    @Autowired
    private OrdersService  ordersService;

    /**
     * 商家条件查询
     * @param dto
     * @return
     */
    @GetMapping("/conditionSearch")
    public Result<PageResult> conditionSearchPage(OrdersPageQueryDTO dto){
        PageResult pageResult = ordersService.conditionSearchPage(dto);
        return Result.success(pageResult);
    }

    /**
     * 商家接单
     * @param orders
     * @return
     */
    @PutMapping("/confirm")
    public Result accept(@RequestBody Orders orders){
        ordersService.accept(orders);
        return Result.success();
    }

    /**
     * 商家拒单
     * @param dto
     * @return
     */
    @PutMapping("/rejection")
    public Result rejection(@RequestBody OrdersRejectionDTO dto){
        ordersService.rejection(dto);
        return Result.success();
    }

    /**
     * 商家取消订单
     * @param dto
     * @return
     */
    @PutMapping("/cancel")
    public Result cancel(@RequestBody OrdersCancelDTO dto){
        ordersService.adminCancel(dto);
        return Result.success();
    }

    /**
     * 商家点击派送
     * @param orderId
     * @return
     */
    @PutMapping("/delivery/{id}")
    public Result delivery(@PathVariable("id") Long orderId){
        ordersService.delivery(orderId);
        return Result.success();
    }

    @PutMapping("/complete/{id}")
    public Result complete(@PathVariable("id") Long orderId){
        ordersService.complete(orderId);
        return Result.success();
    }

    @GetMapping("/details/{id}")
    public Result<OrderVO> orderDetail(@PathVariable("id") Long id){
        OrderVO vo = ordersService.orderDetail(id);
        return Result.success(vo);
    }

    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> statistics(){
        OrderStatisticsVO vo = ordersService.statistics();
        return Result.success(vo);
    }

}
